package com.zhong.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhong.blog.mapper.BlogMapper;
import com.zhong.blog.pojo.Blog;
import com.zhong.blog.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BlogServiceImpl implements BlogService {

    @Autowired
    BlogMapper blogMapper;

    @Override
    public List<Blog> selectList() {
        QueryWrapper<Blog> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("create_time");
        List<Blog> blogs = blogMapper.selectList(wrapper);
        return blogs;
    }

    @Override
    public void save(Blog blog) {
        blogMapper.insert(blog);
    }

    @Override
    public Blog queryById(Integer blogid) {
        Blog blog = blogMapper.selectById(blogid);
        return blog;
    }

    @Override
    public int updata(Blog blog) {
        QueryWrapper<Blog> wrapper = new QueryWrapper<>();
        wrapper.eq("id",blog.getId());
        int update = blogMapper.update(blog, wrapper);
        return update;
    }

    @Override
    public List<Blog> selectListByKey(String key) {
        QueryWrapper<Blog> wrapper = new QueryWrapper<>();
        wrapper.like("title",key);
        List<Blog> blogs = blogMapper.selectList(wrapper);
        return blogs;
    }


}
